import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/app_colors.dart';
import 'package:xvideos/hj_page/mine_business/mine_setting/bind_phone_logic.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

enum PhonePageType {
  bind('绑定手机', 1, '立即绑定'),
  find('找回账号', 2, '立即找回');

  final int type;
  final String title;
  final String buttonTitle;
  const PhonePageType(this.title, this.type, this.buttonTitle);
}

class BindPhonePage extends StatelessWidget {
  static const String routeName = '/setting/bindphone';
  const BindPhonePage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<BindPhoneLogic>(
      init: BindPhoneLogic(),
      builder: (controller) => Scaffold(
        appBar: AppBar(
          title: Text(controller.pageType.title),
        ),
        body: Padding(
          padding: EdgeInsets.only(left: 16, right: 16, top: 47),
          child: Container(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  width: double.infinity,
                  height: 42,
                  padding: EdgeInsets.symmetric(horizontal: 12),
                  child: Row(
                    children: [
                      Text(
                        '手机号',
                        style: TextStyle(color: Colors.white.withOpacity(0.9), fontSize: 16),
                      ),
                      12.sizeBoxW,
                      Expanded(
                        child: TextField(
                          controller: controller.phoneCtr,
                          style: TextStyle(
                            color: Colors.white.withOpacity(0.9),
                            fontSize: 14,
                          ),
                          maxLength: 11,
                          decoration: InputDecoration(
                              border: InputBorder.none,
                              hintText: '请输入手机号码',
                              isCollapsed: true,
                              contentPadding: EdgeInsets.zero,
                              counterText: '',
                              hintStyle: TextStyle(color: Colors.white.withOpacity(0.5), fontSize: 14)),
                        ),
                      )
                    ],
                  ),
                ),
                10.sizeBoxH,
                Divider(
                  height: .5,
                  color: Colors.white.withOpacity(.05),
                ),
                30.sizeBoxH,
                Container(
                  width: double.infinity,
                  height: 42,
                  padding: EdgeInsets.symmetric(horizontal: 12),
                  child: Row(
                    children: [
                      Text(
                        '验证码',
                        style: TextStyle(color: Colors.white.withOpacity(0.9), fontSize: 16),
                      ),
                      12.sizeBoxW,
                      Expanded(
                        child: TextField(
                          controller: controller.codeCtr,
                          style: TextStyle(
                            color: Colors.white.withOpacity(0.9),
                            fontSize: 14,
                          ),
                          maxLength: 6,
                          decoration: InputDecoration(
                              border: InputBorder.none,
                              hintText: '请输入手机验证码',
                              isCollapsed: true,
                              contentPadding: EdgeInsets.zero,
                              counterText: '',
                              hintStyle: TextStyle(color: Colors.white.withOpacity(0.5), fontSize: 14)),
                        ),
                      ),
                      12.sizeBoxW,
                      GestureDetector(
                        onTap: () => controller.onSendCode(),
                        child: ValueListenableBuilder(
                          valueListenable: controller.countDownNof,
                          builder: (BuildContext context, int value, Widget? child) {
                            final iscountdown = value > -1;
                            return Container(
                              padding: EdgeInsets.symmetric(horizontal: 4, vertical: 4),
                              child: Text(
                                iscountdown ? '${60 - value}秒' : '获取验证码',
                                style: TextStyle(color: Colors.white.withOpacity(0.5), fontSize: 12),
                              ),
                            );
                          },
                        ),
                      )
                    ],
                  ),
                ),
                10.sizeBoxH,
                Divider(
                  height: .5,
                  color: Colors.white.withOpacity(.05),
                ),
                30.sizeBoxH,
                GestureDetector(
                  onTap: () => controller.onBindPhone(),
                  child: Container(
                    width: double.infinity,
                    height: 44,
                    alignment: Alignment.center,
                    child: Text(
                      controller.pageType.buttonTitle,
                      style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
                    ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(3),
                      color: AppColors.actionRed,
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
